package com.kuang.controller.pfsi;

import com.kuang.pojo.AstControllerHeart;
import com.kuang.pojo.pfsi.AstPfsiDeviceStateMsg;
import com.kuang.service.asset.AstControllerHeartService;
import com.kuang.service.pfsi.AstPfsiDeviceStateMsgService;
import lombok.extern.log4j.Log4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/asset/")
@Log4j
public class AstPfsiDeviceStateMsgController {

    @Resource
    AstPfsiDeviceStateMsgService astPfsiDeviceStateMsgService;

    /**
     * 获取设备心跳数据
     * @param model
     * @return
     */
    @RequestMapping("getAstPfsiDeviceStateMsgs")
    public String getAstPfsiDeviceStateMsgs(Model model){
        List<AstPfsiDeviceStateMsg> astPfsiDeviceStateMsgs = astPfsiDeviceStateMsgService.selectAll();
        model.addAttribute("datas",astPfsiDeviceStateMsgs);
        model.addAttribute("device_code","");
        model.addAttribute("ver","");
        return "pfsi/ast_pfsi_device_state_msg_list";
    }

    /**
     * 获取设备心跳数据通过条件
     * @param model
     * @return
     */
    @PostMapping("getAstPfsiDeviceStateMsgsByExample")
    public String getAstPfsiDeviceStateMsgsByExample(AstPfsiDeviceStateMsg astPfsiDeviceStateMsg,Model model){
        List<AstPfsiDeviceStateMsg> astPfsiDeviceStateMsgs = astPfsiDeviceStateMsgService.selectAllByExample(astPfsiDeviceStateMsg);
        model.addAttribute("datas",astPfsiDeviceStateMsgs);
        model.addAttribute("device_code",astPfsiDeviceStateMsg.getDevice_code());
        model.addAttribute("ver",astPfsiDeviceStateMsg.getVer());
        return "pfsi/ast_pfsi_device_state_msg_list";
    }

    /**
     * 获取设备信息通过id
     * @param model
     * @return
     */
    @RequestMapping("getAstPfsiDeviceStateMsgsById/{id}")
    public String getAstPfsiDeviceStateMsgsById(@PathVariable("id") String id, Model model){
        AstPfsiDeviceStateMsg astPfsiDeviceStateMsg = new AstPfsiDeviceStateMsg();
        astPfsiDeviceStateMsg.setAst_pfsi_device_state_msg_id(id);
        List<AstPfsiDeviceStateMsg> astPfsiDeviceStateMsgs = astPfsiDeviceStateMsgService.selectAllByExample(astPfsiDeviceStateMsg);
        model.addAttribute("data",astPfsiDeviceStateMsgs.get(0));
        return "pfsi/ast_pfsi_device_state_msg_from";
    }

}
